package excise01;

class PrintEven extends  Thread{
    @Override
    public void run() {
        for(int i=1;i<=100;i++){
            if(i % 2 == 0) {
                System.out.println(Thread.currentThread().getName() + ":" + i);
            }
        }
    }
}

class PrintOdd extends Thread{
    @Override
    public void run() {
        for(int i=1;i<=100;i++){
            if(i % 2 != 0) {
                System.out.println(Thread.currentThread().getName() + ":" + i);
            }
        }
    }
}

public class Test {
    public static void main(String[] args) {
        /*方法一
        PrintEven p1 = new PrintEven();
        p1.start();

        PrintOdd p2 = new PrintOdd();
        p2.start();
        */

        //方法二:创建Thread类的匿名子类的匿名对象
        new Thread(){
            public void run() {
                for(int i=1;i<=100;i++){
                    if(i % 2 == 0) {
                        System.out.println(Thread.currentThread().getName() + ":" + i);
                    }
                }
            }

        }.start();

        new Thread(){
            public void run() {
                for(int i=1;i<=100;i++){
                    if(i % 2 != 0) {
                        System.out.println(Thread.currentThread().getName() + ":" + i);
                    }
                }
            }
        }.start();

        //方法三：使用实现Runnable接口的方式：提供了Runnable接口匿名实现类的匿名对象
        new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i=1;i<=100;i++){
                    if(i % 2 == 0) {
                        System.out.println(Thread.currentThread().getName() + ":" + i);
                    }
                }

            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i=1;i<=100;i++){
                    if(i % 2 != 0) {
                        System.out.println(Thread.currentThread().getName() + ":" + i);
                    }
                }

            }
        }).start();

    }
}
